﻿using JamesZhao.Engine.Graphics.Effects;
using JamesZhao.Engine.Graphics.Geometry;
using JamesZhao.Engine.Graphics.Surfaces;

namespace JamesZhao.Engine.Graphics.Visuals
{
    class TerrainDrawable : Drawable
    {
        public ColorSurface HeightMap { get; set; }
        public GeometryBuffer TerrainGeom { get; private set; }

        public override void RenderWithGpuProgram(GraphicsDevice device, Camera camera, GpuProgram gpuProgram)
        {
            if (TerrainGeom == null)
            {
                TerrainGeom = new GeometryBuffer(device);
                TerrainGeom.InitializeFrom(MeshData.LoadPlaneMesh(5, 1));
            }
            if (Material == null)
            {
                Material = new TerrainMaterial(device);
            }
            ApplyCameraConstants(Material, camera);
            RenderWithGpuProgram(device, Material);
        }
        public override void RenderWithGpuProgram(GraphicsDevice device, GpuProgram gpuProgram)
        {
            Material.ApplyInputLayout(device);
            TerrainGeom.ApplyBuffersAndTopology(device);
            RenderPasses(device, Material, TerrainGeom);
        }
    }
}
